home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / misc / football / exec / writematch.rexx < prev   
OS/2 REXX Batch file  |  1999-11-29  |  6KB  |  188 lines

  1. /* ***********************************************************************
  2.  
  3.    WRITE MATCH PROGRAM FOR FOOTBALL REXX SUITE
  4.   ---------------------------------------------
  5.                    Copyright  Mark Naughton 1997
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  
  11.  1.0       080597   Created. Designed to be called from Gameplay to write
  12.                     the score directly to the Schedule file, giving an
  13.                     error if the match has been played, leaving Gameplay
  14.                     to update the Learn file.
  15.            100597   Changed command for deleting the Game.Stored file. Had
  16.                     to set 'sdcount' to 1 as lines were being missed in the
  17.                     recreation as the first was being stored at 0 instead
  18.                     of 1 which was where the loop started. Had to amend
  19.                     the loop which wrote it back as it added one extra
  20.                     line which wasn't required. Swapped parameters in the
  21.                     'pos' statement when checking the matches as it was
  22.                     always overwriting matches that had been played.
  23.            100697   Changed position that the away team is picked from the
  24.                     argument to 1 from 2. Was giving invalid values.
  25.                     Changed method again, a draw meant that the positions
  26.                     picked up were one out as it went for the 1st occurrence.
  27.  1.1       240499   Jan Andersen reported a problem with teams with numerics
  28.                     in their name and that the schedule was not being updated.
  29.                     Reworked the code for updating the schedule - much better!
  30.  1.2       210899   Found bug in code which updates the match - Two similar
  31.                     team names could not distinguish where they were in the
  32.                     match arg - refused to write. Fixed.
  33.            250899   Added error msg to file check. Fixed bug where similar
  34.                     team names confused the code which overwrote the wrong
  35.                     match - the match is now split with "*" making it
  36.                     easier to pase.
  37.            270899   Converted to use locale. Some error messages, before
  38.                     reading the locale, will still be in English.
  39.  
  40.  
  41. **************************************************************************
  42.  
  43. Procedure
  44. ---------
  45.  
  46. 1. Split argument into league-name and match.
  47. 2. Check schedule file exists. If file-indicator exists then erase it.
  48. 3. Read Schedule file into an array.
  49. 4. Using the teams in the array, split into teams and use this as a match
  50.    against the teams from the game. When found, overwrite the scores.
  51. 5. If a match has been played and updated, then rewrite the Schedule file
  52.    back. Then write the file-indicator to tell Gameplay that a match has
  53.    been stored. Then exit.
  54.  
  55. ************************************************************************** */
  56. PARSE ARG league_file
  57.  
  58. version      = 1
  59. input_file   = '.sf'
  60. output_file  = 'RAM:Game.stored'
  61. separator    = '*'
  62. sdlines.     = '???'
  63. sdcount      = 1
  64. not_played   = '__   __'
  65. league_file  = "Data/"league_file
  66.  
  67. if open(datafile,"Data/Football.locale",'r') then do
  68.    line = readln(datafile)
  69.    locdir = strip(line)
  70.    close(datafile)
  71. end
  72. else do
  73.    say
  74.    say "ERROR :    (WriteMatch)"
  75.    say
  76.    say "Cannot read 'Data/Football.locale' for the locale settings."
  77.    exit
  78. end
  79.  
  80. locdir = locdir"Exec/WriteMatch.data"
  81.  
  82. if open(datafile,"ENV:FootballRXPath",'r') then do
  83.    line = readln(datafile)
  84.    rxdir = strip(line)
  85.    close(datafile)
  86. end
  87. else
  88.    rxdir = "SYS:Rexxc/"
  89.  
  90. if exists(locdir) > 0 then do
  91.   address command rxdir'rx 'locdir
  92.   VarCount = getclip('VarCount')
  93.   do i = 1 to VarCount
  94.     interpret getclip('var.'i)
  95.   end
  96. end
  97. else do
  98.    say
  99.    say "ERROR :    (WriteMatch)"
  100.    say
  101.    say "Cannot find '"locdir"' to read locale settings."
  102.    exit
  103. end
  104.  
  105. parse var league_file league " " match
  106. parse var match tt1 "*" ss1 "*" ss2 "*" tt2
  107.  
  108. if exists(league || input_file) = 0 then do
  109.    say
  110.    say wm_error
  111.    say
  112.    say wm_one"'"league_file||input_file"'."
  113.    exit
  114. end
  115.  
  116. if exists(output_file) > 0 then
  117.    address command 'delete >NIL: 'output_file
  118.  
  119. if open(datafile3,league || input_file,'r') then do
  120.    do while ~eof(datafile3)
  121.       line = readln(datafile3)
  122.       sdlines.sdcount = strip(line)
  123.       sdcount         = sdcount + 1
  124.    end
  125.    close(datafile3)
  126. end
  127. else do
  128.    say
  129.    say wm_error
  130.    say
  131.    say wm_two"'"league || input_file"' "wm_three
  132.    exit
  133. end
  134.  
  135. tt1 = strip(tt1)
  136. tt2 = strip(tt2)
  137. ss1 = strip(ss1)
  138. ss2 = strip(ss2)
  139. marker = 0
  140. do i=1 to sdcount
  141.    team1 = strip(substr(sdlines.i,1,30))
  142.    team2 = strip(substr(sdlines.i,41,30))
  143.    if tt1 == team1 & tt2 == team2 then do
  144.  
  145.       if pos(not_played,sdlines.i) > 0 then do
  146.          sdlines.i = overlay(right(ss1,2),sdlines.i,32)
  147.          sdlines.i = overlay(right(ss2,2),sdlines.i,37)
  148.          marker = 1
  149.          leave
  150.       end
  151.       else
  152.          marker = 0
  153.    end
  154. end
  155.  
  156.  
  157. if marker = 1 then do
  158.    if open(datafile3,league || input_file,'w') then do
  159.       do i=1 to sdcount-1
  160.          if i < sdcount-1 then
  161.             writeln(datafile3,sdlines.i)
  162.          else
  163.             writech(datafile3,sdlines.i)
  164.       end
  165.       close(datafile3)
  166.       if open(datafile1,output_file,'w') then do
  167.          writeln(datafile1,"Game stored in '"league||input_file"'.")
  168.          close(datafile1)
  169.       end
  170.       else do
  171.          say
  172.          say wm_error
  173.          say
  174.          say wm_five
  175.          exit
  176.       end
  177.    end
  178.    else do
  179.       say
  180.       say wm_error
  181.       say
  182.       say wm_two"'"league || input_file"' "wm_four
  183.    end
  184. end
  185.  
  186. exit
  187.  
  188. /* *********************************************************************** */